package com.bango.testapp;

import net.rim.device.api.applicationcontrol.ApplicationPermissions;
import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
import net.rim.device.api.ui.UiApplication;

import com.bango.blackberry.BangoAgent;

public class TestApp extends UiApplication {
	public TestApp() {
		pushScreen(new TestAppScreen());
	}

	public static void main(String[] args) {
		TestApp theApp = new TestApp();
		setupPermissions();

		// Set configuration options here

		// Call start session here
		// BangoAgent.onStartSession([Your Application Id]);

		theApp.enterEventDispatcher();

	}

	public static void setupPermissions() {
		ApplicationPermissionsManager man = ApplicationPermissionsManager
				.getInstance();
		int[] requiredPerms = new int[] {
				ApplicationPermissions.PERMISSION_EXTERNAL_CONNECTIONS,
				ApplicationPermissions.PERMISSION_INTERNAL_CONNECTIONS,
				ApplicationPermissions.PERMISSION_LOCATION_API,
				ApplicationPermissions.PERMISSION_WIFI };
		ApplicationPermissions perms = man.getApplicationPermissions();
		boolean change = false;
		for (int i = 0; i < requiredPerms.length; i++) {
			if (perms.containsPermissionKey(requiredPerms[i])) {
				if (perms.getPermission(requiredPerms[i]) != ApplicationPermissions.VALUE_ALLOW) {
					change = true;
					perms.addPermission(requiredPerms[i]);
				}
			} else {
				change = true;
				perms.addPermission(requiredPerms[i]);
			}
		}
		if (change) {
			man.invokePermissionsRequest(perms);
		}
	}

}
